/**
 * Created by Allen on 2018/2/26.
 */
import { messages } from 'share/common';
import React from 'react';
import { connect } from 'react-redux';
import { Tabs, } from 'antd';
import 'styles/supplier-management/invoice-management/invoice-management.scss';
import SupplierInvoice from './invoice-management-details/supplier-invoice';
import InvoiceInspection from './invoice-management-details/invoice-Inspection';
import TimedReminder from './invoice-management-details/timed-reminder';
import ExpirationReminder from './invoice-management-details/expiration-reminder';
import InvoiceCheck from './invoice-management-details/invoice-check';

const TabPane = Tabs.TabPane;

class InvoiceManagement extends React.Component {
  constructor(props) {
    super(props);
    this.state = {
      loading: false,
      weChatInvoiceDisabled: false,
      aliPayInvoiceDisabled: false, // 启用支付宝
      emailInvoiceDisabled: false,//启用邮箱导入发票
      status: 'SUPPLIER',
    };
  }

  //渲染Tabs
  renderTabs() {
    const { weChatInvoiceDisabled, aliPayInvoiceDisabled, emailInvoiceDisabled } = this.state;
    const { tenantMode } = this.props;
    let tabs = tenantMode ? [
      {
        key: 'SUPPLIER',
        name: messages('setting.key735'/*发票开通*/),
        template: <SupplierInvoice onChange={this.handleWatchPayWay}/>
      },
      {
        key: 'CHECK',
        name: messages('supplier.key231')/*发票校验*/,
        template: <InvoiceCheck />
      },
      {
        key: 'INSPECTION',
        name: messages('supplier.key227')/*查验服务*/,
        template: <InvoiceInspection serviceTypeCode='CHECK_INVOICE'/>
      },
      {
        key: 'IDENTIFICATION',
        name: messages('supplier.key228')/*发票识别服务*/,
        template: <InvoiceInspection serviceTypeCode='OCR'/>
      }
    ] : [
      {
        key: 'SUPPLIER',
        name: messages('setting.key735'/*发票开通*/),
        template: <SupplierInvoice onChange={this.handleWatchPayWay}/>
      },
      {
        key: 'TIMED',
        name: messages('setting.key120'/*定时提醒*/),
        template: <TimedReminder/>
      },
      {
        key: 'EXPIRATION',
        name: messages('setting.key736'/*发票过期提醒*/),
        template: <ExpirationReminder weChatInvoiceDisabled={weChatInvoiceDisabled} aliPayInvoiceDisabled={aliPayInvoiceDisabled} emailInvoiceDisabled={emailInvoiceDisabled}/>
      },
    ];
    return (
      tabs.map(tab => {
        return (
          <TabPane tab={tab.name} key={tab.key}>
            {tab.template}
          </TabPane>
        );
      })
    );
  }

  handleWatchPayWay = (params) => {
    this.setState(params)
  };

  render() {
    const { status } = this.state;
    return (
      <div className="invoice-management">
        <h3 className="header-title">{messages('setting.key757'/*发票管理*/)}</h3>
        <Tabs defaultActiveKey={status} onChange={this.onChangeTabs} type="card">
          {this.renderTabs()}
        </Tabs>
      </div>
    );
  }
}

InvoiceManagement.contextTypes = {
  router: React.PropTypes.object
};

function mapStateToProps(state) {
  return {
    tenantMode: state.main.tenantMode,
  };
}

export default connect(mapStateToProps)(InvoiceManagement);
